package com.imti.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.imti.Api.CommonPage;
import com.imti.Api.CommonResult;
import com.imti.entity.Doctor;
import com.imti.service.DoctorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Doctor)表控制层
 *
 * @author makejava
 * @since 2023-01-30 15:52:20
 */
@RestController
@RequestMapping("doctor")
public class DoctorController {
    /**
     * 服务对象
     */
    @Resource
    private DoctorService doctorService;

    /**
     * 使用mybatis的pagehelper分页插件进行分页
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/getDocPageByPageHelper")
    public CommonResult getDocPageByPageHelper(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

        PageHelper.startPage(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(doctorService.list()));
    }

    /**
     * 使用mybatisplus分页插件进行分页
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/getDocPageByInterceptor")
    public CommonResult getDocPageByInterceptor(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

        Page page = new Page(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(doctorService.getDoc(page)));
    }

    /**
     * 自己写sql的limit进行分页
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/getDocPageBySQLLimit")
    public CommonResult getDocPageBySQLLimit(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

        return CommonResult.success(CommonPage.restPage(doctorService.getDocBySQLLimit(pageNum, pageSize)));
    }
}

